package net.hserver.watermark.ui;

import javax.swing.*;
import java.awt.*;

public class MultiLineCellRenderer extends JTextArea implements ListCellRenderer<String> {
    private JLabel label;

    public MultiLineCellRenderer() {
        setLineWrap(true); // 允许换行
        setWrapStyleWord(true); // 按单词换行
        setOpaque(true);
    }

    @Override
    public Component getListCellRendererComponent(JList<? extends String> list, String value, int index, boolean isSelected, boolean cellHasFocus) {
        setText(value);
        if (isSelected) {
            setBackground(list.getSelectionBackground());
            setForeground(list.getSelectionForeground());
        } else {
            setBackground(list.getBackground());
            setForeground(list.getForeground());
        }
        return this;
    }
}
